package com.cskaoyan.controller;

import com.cskaoyan.bean.*;
import com.cskaoyan.bean.dashboardvo.DashBoardVo;
import com.cskaoyan.bean.data.*;
import com.cskaoyan.bean.usermodelbo.*;
import com.cskaoyan.service.UserService;
import com.cskaoyan.util.StringUtils;
import com.cskaoyan.util.ValidateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: yudefu
 * @date 2021年06月04日  18:58
 * @description:
 */
@RestController
@RequestMapping("admin")
public class AdminUserController {

    @Autowired
    UserService userService;


    /**
     * 首页模块
     *
     * @return
     */
    @RequestMapping("dashboard")
    public BaseRespVo dashBoardVo() {

        DashBoardVo dashBoardVo = userService.getDashBoardData();

        return BaseRespVo.ok(dashBoardVo);
    }


    //下面是用户模块

    /**
     * 会员管理之获取会员信息
     */
    @RequestMapping("/user/list")
    public BaseRespVo getUserList(UserReq userReq) {

//        UserData userData = userService.selectUserData(page, limit, sort, order);

//        UserData userData = userService.getUserList(userReq);
        BaseData<User> userData = userService.getUserList(userReq);

  /*      BaseRespVo baseRespVo = new BaseRespVo();
        baseRespVo.setErrno(0);
        baseRespVo.setErrmsg("成功");
        baseRespVo.setData(userData);
*/
        return BaseRespVo.ok(userData);
    }


    /**
     * 会员管理之收货地址
     */
    @RequestMapping("/address/list")
    public BaseRespVo getAddressList(@Validated AddressReq addressReq, BindingResult bindingResult) {



        if (!(StringUtils.adminUserParamVerification(addressReq.getUserId()))) {
            return BaseRespVo.fail(402, "参数值不对");
        }

//        AddressData addressData = userService.getAddressList(addressReq);
        BaseData<Address> addressData = userService.getAddressList(addressReq);


        return BaseRespVo.ok(addressData);
    }


    /**
     * 会员管理之会员收藏
     */
    @RequestMapping("/collect/list")
    public BaseRespVo getCollectList(CollectReq collectReq) {

        if (!(StringUtils.adminUserParamVerification(collectReq.getUserId())) || !(StringUtils.adminUserParamVerification(collectReq.getValueId()))) {
            return BaseRespVo.fail(402, "参数值不对");
        }

//        CollectData collectData = userService.getCollectList(collectReq);
        BaseData<Collect> collectData = userService.getCollectList(collectReq);

        return BaseRespVo.ok(collectData);
    }


    /**
     * 会员管理之会员足迹
     */
    @RequestMapping("/footprint/list")
    public BaseRespVo getFootPrintList(FootPrintReq footPrintReq) {

        if (!(StringUtils.adminUserParamVerification(footPrintReq.getUserId())) || !(StringUtils.adminUserParamVerification(footPrintReq.getGoodsId()))) {
            return BaseRespVo.fail(402, "参数值不对");
        }

//        FootPrintData footPrintData = userService.getFootPrintList(footPrintReq);
        BaseData<FootPrint> footPrintData = userService.getFootPrintList(footPrintReq);


        return BaseRespVo.ok(footPrintData);
    }


    /**
     * 会员管理之搜索历史
     */
    @RequestMapping("/history/list")
    public BaseRespVo getHistoryList(HistoryReq historyReq) {

        if (!(StringUtils.adminUserParamVerification(historyReq.getUserId()))) {
            return BaseRespVo.fail(402, "参数值不对");
        }

//        SearchHistoryData searchHistoryData = userService.getHistoryList(historyReq);
        BaseData<SearchHistory> searchHistoryData = userService.getHistoryList(historyReq);


        return BaseRespVo.ok(searchHistoryData);
    }


    @RequestMapping("/feedback/list")
    public BaseRespVo getFeedbackList(FeedbackReq feedbackReq) {

        if (!(StringUtils.adminUserParamVerification(feedbackReq.getId()))) {
            return BaseRespVo.fail(402, "参数值不对");
        }

//        FeedbackData feedbackData = userService.getFeedbackList(feedbackReq);

        BaseData<Feedback> feedbackData = userService.getFeedbackList(feedbackReq);

        return BaseRespVo.ok(feedbackData);
    }


}
